package com.example.redis.redis.userServer.impl;

import com.alibaba.fastjson.JSON;
import com.example.redis.redis.Dao.Mapper;
import com.example.redis.redis.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
//@CacheConfig(cacheNames = "users")
public class UserInfoImpl implements com.example.redis.redis.userServer.UserInfo {
    @Autowired
    private Mapper mapper;

    @Override
    @Cacheable(value = "all", key = "2")
    public UserInfo findByUsername(String name) {
        UserInfo mapperByUsername = mapper.findByUsername(name);
        System.out.println("数据库读取数据....");
        return mapperByUsername;
    }

    @Override
    @CacheEvict(value = "all", key = "2")
    public void updateByusername(Map map) {
        mapper.updateByusername(map);
    }
}
